<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/TestPlan' }"><i class="el-icon-s-home" style="margin-right: 15px;font-size: 16px"></i>试验方案</el-breadcrumb-item>
      <el-breadcrumb-item v-if="$route.query.sign === 'edit'"><i class="el-icon-menu" style="margin-right: 15px;font-size: 16px"></i>编辑试验方案</el-breadcrumb-item>
      <el-breadcrumb-item v-else><i class="el-icon-menu" style="margin-right: 15px;font-size: 16px"></i>新增试验方案</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="info">
      <el-card shadow="always" style="margin-top: 30px;">
        <div slot="header"><el-row><div class="rectangularBar"></div><div class="testPlanTitle">试验方案</div></el-row></div>
        <el-form :model="planFrom" :rules="planRules" ref="planFrom" label-width="100px">
          <el-form-item label="方案名称" prop="testPlanName">
            <el-input v-model="planFrom.testPlanName" placeholder="请输入方案名称" size="small" clearable></el-input>
          </el-form-item>
          <el-form-item label="方案描述">
            <el-input type="textarea" clearable :rows="4" placeholder="方案描述主要是对本次方案使用场景的介绍" v-model="planFrom.description"></el-input>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card shadow="always" style="margin-top: 20px;">
        <div slot="header">
          <el-row>
            <div class="rectangularBar"></div><div class="testPlanTitle">试验设备</div>
            <div class="newButtonPosition"><el-button class="global_add" type="text" size="small" @click="getTestInstList">选择设备</el-button></div>
          </el-row>
        </div>
        <el-dialog title="选择设备" :visible.sync="dialogVisible" :close-on-click-modal="false" :close-on-press-escape="false">
          <el-row>
            <el-col :xs="4" :sm="3" :xl="3" :lg="3"><span style="line-height:2;">工位名称</span></el-col>
            <el-col :xl="3" :lg="8">
              <el-select v-model="workePosit" @change="selectPositAndStatus" size="small" placeholder="工位名称" style="width:100%">
                <el-option v-for="item in workePositList" :key="item.station_id" :label="item.station_name" :value="item.station_id"></el-option>
              </el-select>
            </el-col>
            <el-col :xl="3" :lg="3" style="margin-left:20px"><span style="line-height:2">设备状态</span></el-col>
            <el-col :xl="3" :lg="8">
              <el-select v-model="instStatus" @change="selectPositAndStatus" size="small" placeholder="设备状态" style="width:100%">
                <el-option label="所有" value="all"></el-option>
                <el-option label="在线" value="在线"></el-option>
                <el-option label="离线" value="离线"></el-option>
              </el-select>
            </el-col>
          </el-row>
          <el-table row-key="instr_id" ref="multipleTable" stripe :data="displayInstList" v-loading="dataLoading[1]" tooltip-effect="dark" border @selection-change="handleSelectionChange" :header-cell-style="{background:'#E8E8E8'}" class="popInstrumentTable">
            <el-table-column type="selection" width="55" align="center"></el-table-column>
            <el-table-column prop="instr_name" label="设备名称" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="model" label="设备型号" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="spec" label="设备规格" align="center" show-overflow-tooltip ></el-table-column>
            <el-table-column prop="instr_number" label="设备编号" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column prop="station_name" label="工位名称" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column label="状态" width="90" align="center">
              <template slot-scope="scope">
                <el-row>
                  <el-col :span="4"><div class="circleStyle" :style="{'background-color':(scope.row.online_status === '在线' ?'#009641':'#595757')}"></div></el-col>
                  <el-col :span="12" :style="{'color':(scope.row.online_status === '在线')? '#57A2FF':'#595757'}">{{scope.row.online_status}}</el-col>
                </el-row>
              </template>
            </el-table-column>
          </el-table>
          <el-row>
            <el-button type="primary" class="confirmButton" @click="confirmSelect">确 定</el-button>
            <el-button plain class="variableCanelButton" @click="cancelSelect">取 消</el-button>
          </el-row>
        </el-dialog>
        <el-table v-loading="dataLoading[0]" ref="singleTable" stripe :data="testPlanInst" style="width: 100%">
          <el-table-column type="index" label="#" width="100" align="center"></el-table-column>
          <el-table-column property="instr_name" label="设备名称" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column property="model" label="设备型号" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column property="spec" label="设备规格" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column property="instr_number" label="设备编号" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column property="station_name" label="工位名称" align="center" show-overflow-tooltip></el-table-column>
          <el-table-column property="operation" label="操作" align="center" width="230">
            <template slot-scope="scope">
              <i class="el-icon-delete" style="font-size:23px;color: #E83131;margin-left: 10px;" @click="deleteInstrument(scope.$index, scope.row)"></i>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <el-card shadow="always" style="margin-top: 20px;">  <!--公共参数card-->
        <div slot="header">
          <el-row><div class="rectangularBar"></div><div class="testPlanTitle">公共参数</div></el-row>
        </div>
        <el-form :model="publicParam" :rules="publicParamRules" ref="publicParam" label-width="130px" size="small" style="margin: 10px 40px 0 20px">
          <el-row>
            <!-- <el-col :span="8">
              <el-form-item label="试品类型：" prop="productName" :rules="{ required: true, message: '请选择试品类型', trigger: 'change' }">
                <el-select v-model="publicParam.productName" @change="getProdTempName" placeholder="请选择试品类型" style="width:100%" clearable>
                  <el-option v-for="item in productNameList" :key="item.prod_id" :label="item.pk_ch_name" :value="item.prod_id"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
            <el-col :span="8">
              <el-form-item label="试品模板：" prop="prodTempName" :rules="{ required: true, message: '请选择试品模板', trigger: 'change' }">
                <el-select v-model="publicParam.prodTempName" @change="getProdPartInfo" placeholder="请选择试品模板" style="width:100%" clearable>
                  <el-option v-for="item in prodTempList" :key="item.tplt_id" :label="item.tplt_name" :value="item.tplt_id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="适用海拔：" prop="elevation" :rules="[{ required: true, message: '请输入适用海拔', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                <el-input v-model="publicParam.elevation" placeholder="请输入适用海拔" clearable><template slot="append">&nbsp;&nbsp;m&nbsp;&nbsp;</template></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="海拔参数m：" prop="elevaParam" :rules="[{ required: true, message: '请输入海拔参数', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                <el-input v-model="publicParam.elevaParam" placeholder="请输入海拔参数" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="16">
              <el-form-item label="试验依据标准：" prop="accordStand" :rules="{ required: true, message: '请选择试验依据标准', trigger: 'change' }">
                <el-select clearable v-model="publicParam.accordStand" multiple placeholder="请至少选择一个试验依据标准" style="width:100%">
                  <el-option v-for="item in accordStandList" :key="item.gjb_id" :label="item.gjb_name" :value="item.gjb_id"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-form-item label="试验类型：" prop="testType" :rules="{ required: true, message: '请选择试验类型', trigger: 'change' }">
              <el-select clearable v-model="publicParam.testType"  @change="selectTestType" multiple placeholder="请选择一个或多个试验类型" style="width:100%">
                <el-option v-for="item in testTypeList" :key="item.test_id" :label="item.test_kind" :value="item.test_id"></el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </el-form>
      </el-card>
      <el-card shadow="always" style="margin-top: 20px;">  <!--参数配置card-->
        <div slot="header"><el-row><div class="rectangularBar"></div><div class="testPlanTitle">参数配置</div></el-row></div>
        <el-tabs v-model="activeName" style="margin: 0 20px 0px 20px">
          <el-tab-pane label="雷电冲击耐受电压试验" name="first" v-if="showliEquip">
            <el-form :model="liEquipParams" :rules="liEquipParamsRules" ref="liEquipParams" label-width="125px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="充电时间：" prop="chargTime" :rules="[{ required: true, message: '请输入充电时间', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input clearable v-model="liEquipParams.chargTime" placeholder="请输入充电时间"><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="首次充电电压：" prop="firChargVal" :rules="[{ required: true, message: '请输入首次充电电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                    <el-input clearable v-model="liEquipParams.firChargVal" placeholder="请输入首次充电电压"><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KV&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                  <el-form-item label="老练次数：" prop="runTimes" :rules="[{ required: true, message: '请输入老练次数', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input-number clearable v-model.number="liEquipParams.runTimes" controls-position="right" :min="0" :step="1" style="width: 100%"></el-input-number>
                  </el-form-item>
                </el-col> -->
                <el-col :span="8">
                  <el-form-item label="计数器：" prop="counter" :rules="[{ required: true, message: '请输入数字', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input-number clearable v-model.number="liEquipParams.counter" controls-position="right" :min="0" :step="1" style="width: 100%"></el-input-number>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="连续放电：" prop="discharge" :rules="{ required: true, message: '请选择是否连续放电', trigger: 'change' }">
                    <el-select v-model="liEquipParams.discharge" placeholder="请选择是否连续放电" style="width:100%" clearable>
                      <el-option label="是" value="1"></el-option>
                      <el-option label="否" value="0"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="C：" prop="paramC" :rules="[{ required: true, message: '请输入C值', trigger: 'blur'},{ validator: validPressValue, trigger: 'blur'}]">
                    <el-input v-model="liEquipParams.paramC" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;μF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="C1：" prop="paramC1" :rules="[{ required: true, message: '请输入C1值', trigger: 'blur'},{ validator: validPressValue, trigger: 'blur'}]">
                    <el-input v-model="liEquipParams.paramC1" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="Rf：" prop="paramRf" :rules="[{ required: true, message: '请输入Rf值', trigger: 'blur'},{ validator: validPressValue, trigger: 'blur'}]">
                    <el-input v-model="liEquipParams.paramRf" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ω&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="Rt：" prop="paramRt" :rules="[{ required: true, message: '请输入Rt值', trigger: 'blur'},{ validator: validPressValue, trigger: 'blur'}]">
                    <el-input v-model="liEquipParams.paramRt" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Ω&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form> 
            <div class="formItem"><el-form :model="liEquipForm" :rules="liEquipParamsRules" ref="liEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table stripe :span-method="arraySpanMethod"  :data="liEquipForm.liEquipTableData" border style="width: 100%">
                <el-table-column label="试验部位"   align="center" show-overflow-tooltip>
                   <template slot-scope="scope">
             <span v-if="scope.row.tp_type==1" >{{scope.row.part_name}}</span>
                  <span v-else >{{scope.row.part_id}}</span> 
         
            </template>
                </el-table-column>
                 <!-- <el-table-column label="标志位" prop="flag_bit" align="center" show-overflow-tooltip></el-table-column> -->
                <el-table-column label="原始电压(kVp)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.origin_volt'" :rules=" props.row.if_test==1&&props.row.tp_type==1? [{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.origin_volt" size="mini" placeholder="请输入原始电压" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否试验" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.if_test'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否试验', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_test" size="mini" style="width:100%">
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否校大气" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.if_calair'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否校大气', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_calair" size="mini" v-if="props.row.if_calair !== '2'" style="width:100%">
                        <el-option label="否" value="0"></el-option>
                        <el-option label="是" value="1"></el-option>
                      </el-select>
                    <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'liEquipTableData.' + props.$index + '.percent_volt'" :rules="props.row.tp_type==1? [{ required: true, message: '请输入原始电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.percent_volt" size="mini" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否老练" align="center">
                  <template slot-scope="props">
                    <el-form-item  >
                      <el-select v-model="props.row.if_buffer" size="mini"  style="width:100%">
                        <el-option label="否" value="0"></el-option>
                        <el-option label="是" value="1"></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="工频耐受电压试验" name="second" v-if="showACEquip">
            <el-form :model="acEquipParams"   :rules="acEquipParamsRules" ref="acEquipParams" label-width="130px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="采样间隔：" prop="interval" :rules="[{ required: true, message: '请输入采样间隔', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acEquipParams.interval" placeholder="请输入采样间隔" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="耐压时间：" prop="withstandTime" :rules="[{ required: true, message: '请输入耐压时间', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acEquipParams.withstandTime" placeholder="请输入耐压时间" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                  <el-form-item label="高速设置：" prop="highSpeed" :rules="[{ required: true, message: '请输入高速设置', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acEquipParams.highSpeed" placeholder="请输入高速设置" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col> -->
              </el-row>
              <!-- <el-row>
                <el-col :span="8">
                  <el-form-item label="低速设置：" prop="lowSpeed" :rules="[{ required: true, message: '请输入低速设置', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acEquipParams.lowSpeed" placeholder="请输入低速设置" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
              </el-row> -->
            </el-form>
            <div class="formItem"><el-form :model="acEquipForm" :rules="liEquipParamsRules" ref="acEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table stripe :span-method="arraySpanGpMethod" :data="acEquipForm.acEquipTableData" border style="width: 100%">
                  <el-table-column label="试验部位"  align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
             <span v-if="scope.row.tp_type==1" >{{scope.row.part_name}}</span>
                  <span v-else >{{scope.row.part_id}}</span> 
         
            </template>
                  </el-table-column>
                 <!-- <el-table-column label="标志位" prop="flag_bit" align="center" show-overflow-tooltip></el-table-column> -->
                <el-table-column label="原始电压(kVp)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'acEquipTableData.' + props.$index + '.origin_volt'" :rules="props.row.if_test==1&&props.row.tp_type==1? [{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.origin_volt" size="mini" placeholder="请输入原始电压" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否试验" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'acEquipTableData.' + props.$index + '.if_test'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否试验', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_test" size="mini" style="width:100%">
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否校大气" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'acEquipTableData.' + props.$index + '.if_calair'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否校大气', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_calair" size="mini" v-if="props.row.if_calair !== '2'" style="width:100%">
                        <el-option label="否" value="0"></el-option>
                        <el-option label="是" value="1"></el-option>
                      </el-select>
                      <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'acEquipTableData.' + props.$index + '.percent_volt'" :rules="props.row.tp_type==1? [{ required: true, message: '请输入试验电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.percent_volt" size="mini" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="工频耐受电压试验(湿)" name="fourth" v-if="showWetACEquip">
            <el-form :model="acWetEquipParams" :rules="acEquipParamsRules" ref="acWetEquipParams" label-width="130px" size="small" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-col :span="8">
                  <el-form-item label="采样间隔：" prop="interval" :rules="[{ required: true, message: '请输入采样间隔', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.interval" placeholder="请输入采样间隔" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="耐压时间：" prop="withstandTime" :rules="[{ required: true, message: '请输入耐压时间', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.withstandTime" placeholder="请输入耐压时间" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                  <el-form-item label="高速设置：" prop="highSpeed" :rules="[{ required: true, message: '请输入高速设置', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.highSpeed" placeholder="请输入高速设置" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col> -->
                <el-col :span="8">
                  <el-form-item label="水温：" prop="waterTemp" :rules="[{ required: true, message: '请输入水温', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.waterTemp" placeholder="请输入水温" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;℃&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <!-- <el-col :span="8">
                  <el-form-item label="低速设置：" prop="lowSpeed" :rules="[{ required: true, message: '请输入低速位置', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.lowSpeed" placeholder="请输入低速设置" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col> -->
                <!-- <el-col :span="8">
                  <el-form-item label="水温：" prop="waterTemp" :rules="[{ required: true, message: '请输入水温', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.waterTemp" placeholder="请输入水温" clearable><template slot="append">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;℃&nbsp;&nbsp;&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col> -->
                <el-col :span="8">
                  <el-form-item label="雨水导电率：" prop="rainElect" :rules="[{ required: true, message: '请输入雨水导电率', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.rainElect" placeholder="请输入雨水导电率" clearable><template slot="append">&nbsp;&nbsp;μS/cm&nbsp;&nbsp;</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="水平分量：" prop="horizCompont" :rules="[{ required: true, message: '请输入水平分量', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.horizCompont" placeholder="请输入水平分量" clearable><template slot="append">mm/min</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="垂直分量：" prop="verticalCompont" :rules="[{ required: true, message: '请输入垂直分量', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.verticalCompont" placeholder="请输入垂直分量" clearable><template slot="append">mm/min</template></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <!-- <el-row>
                <el-col :span="8">
                  <el-form-item label="水平分量：" prop="horizCompont" :rules="[{ required: true, message: '请输入水平分量', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.horizCompont" placeholder="请输入水平分量" clearable><template slot="append">mm/min</template></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="垂直分量：" prop="verticalCompont" :rules="[{ required: true, message: '请输入垂直分量', trigger: 'blur'},{ validator: intValiValue, trigger: 'blur'}]">
                    <el-input v-model="acWetEquipParams.verticalCompont" placeholder="请输入垂直分量" clearable><template slot="append">mm/min</template></el-input>
                  </el-form-item>
                </el-col>
              </el-row> -->
            </el-form>
            <div class="formItem"><el-form :model="acWetEquipForm" :rules="liEquipParamsRules" ref="acWetEquipForm" label-width="0px" size="small" :inline-message="true">
              <el-table  :span-method="arraySpanGpMethod" :data="acWetEquipForm.wetACTableData" border stripe style="width: 100%">
                <el-table-column  label="试验部位" align="center" show-overflow-tooltip>
                   <template slot-scope="scope">
             <span v-if="scope.row.tp_type==1" >{{scope.row.part_name}}</span>
                  <span v-else >{{scope.row.part_id}}</span> 
         
            </template>
                </el-table-column>
                <el-table-column label="原始电压(kVp)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.origin_volt'" :rules="props.row.if_test==1&&props.row.tp_type==1?  [{ required: true, message: '请输入原始电压', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.origin_volt" size="mini" placeholder="请输入原始电压" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否试验" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.if_test'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否试验', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_test" size="mini" style="width:100%" >
                        <el-option label="是" value="1"></el-option>
                        <el-option label="否" value="0"></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="是否校大气" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.if_calair'" :rules="props.row.tp_type==1? [{ required: true, message: '请选择是否校大气', trigger: 'change' }]:[]">
                      <el-select v-model="props.row.if_calair" size="mini" v-if="props.row.if_calair !== '2'" style="width:100%">
                        <el-option label="否" value="0"></el-option>
                        <el-option label="是" value="1"></el-option>
                      </el-select>
                      <span v-if="props.row.if_calair === '2'">不允许校大气</span>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column label="试验电压百分比(%)" align="center">
                  <template slot-scope="props">
                    <el-form-item :prop="'wetACTableData.' + props.$index + '.percent_volt'" :rules="props.row.tp_type==1? [{ required: true, message: '请输入试验电压百分比', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]:[]">
                      <el-input v-model="props.row.percent_volt" size="mini" placeholder="请输入试验电压百分比" clearable></el-input>
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column property="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
              </el-table>
            </el-form></div>
          </el-tab-pane>
          <el-tab-pane label="气候防护试验" name="third" v-if="showDefend">
            <el-form :model="defendParams" ref="defendParams" label-width="130px" size="mini" style="margin: 10px 0px 0 10px">
              <el-row>
                <el-form-item label="防护等级" prop="protectId" :rules="{ required: true, message: '请输入防护等级', trigger: 'change' }">
                  <el-select v-model="defendParams.protectId" @change="selectDefendType" multiple placeholder="请选择一个或多个防护等级" style="width:100%" clearable>
                    <el-option v-for="item in defendLevelList" :key="item.protect_id" :label="item.protect_level" :value="item.protect_id"></el-option>
                  </el-select>
                </el-form-item>
              </el-row>
              <el-row>配置试品尺寸(仅支持防护等级为IPX3 IPX4 IPX5 IPX5W IPX6)</el-row>
              <el-table v-if="defendParams.defendTableData.length !== 0" :data="defendParams.defendTableData" border style="width: 100%" :header-cell-style="{background:'#F7F7FB'}">
                <el-table-column property="protectLevel" label="防护等级" show-overflow-tooltip align="center"></el-table-column>
                <el-table-column label="试品长度(m)" align="center">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" :prop="'defendTableData.' + props.$index + '.productLength'" :rules="[{ required: true, message: '请输入试品长度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productLength" size="mini" placeholder="请输入试品长度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
                <el-table-column label="试品宽度(m)" align="center">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" class="defend" :prop="'defendTableData.' + props.$index + '.productWidth'" :rules="[{ required: true, message: '请输入试品宽度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productWidth" size="mini" placeholder="请输入试品宽度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
                <el-table-column label="试品高度(m)" align="center">
                  <template slot-scope="props">
                    <div class="defend"><el-form-item label-width="0px" class="defend" :prop="'defendTableData.' + props.$index + '.productHeight'" :rules="[{ required: true, message: '请输入试品高度', trigger: 'blur'},{ validator: validateValue, trigger: 'blur'}]">
                      <el-input v-model="props.row.productHeight" size="mini" placeholder="请输入试品高度" clearable></el-input>
                    </el-form-item></div>
                  </template>
                </el-table-column>
              </el-table>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </el-card>
      <el-row :gutter="60" style="margin-top: 30px;margin-bottom: 20px;">
        <el-col :span="12" style="text-align: right;"><el-button class="deletButton textBtn" size="small" @click="toCanale">取消修改</el-button></el-col>
        <el-col :span="12"><el-button class="saveButton" type="primary" @click="saveValidate">保存修改</el-button></el-col>
      </el-row>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import sessionStorage from '../../public/storage.js';
const uuid = require('node-uuid');
export default {
  data() {
    const sentencedEmpty = (rule, value, callback) => {
      if (!/^[^\s].*/.test(value)) {
        callback(new Error('首字符不可为空格等空字符'));
      }
      callback();
    }
    return {
      validateValue: (rule, value, callback) => {
        if (!/^\d+(\.\d{1,2})?$/.test(value)) {
          callback(new Error('输入值非法，请输入整数或至多两位小数'));
        }
        callback();
      },
      intValiValue: (rule, value, callback) => {
        if (!/^\d+$/.test(value)) {
          callback(new Error('输入值非法，请输入整数'));
        }
        if (this.showWetACEquip === true && Number(this.acWetEquipParams.interval) > Number(this.acWetEquipParams.withstandTime)) {
          callback(new Error('工频耐受电压试验(湿)耐压时间必须大于采样间隔'));
        }
        if (this.showACEquip === true && Number(this.acEquipParams.interval) > Number(this.acEquipParams.withstandTime)) {
          callback(new Error('工频耐受电压试验耐压时间必须大于采样间隔'));
        }
        callback();
      },
      validPressValue: (rule, value, callback) => {
        if (this.disabledPresValue === false && !/^\d+(\.\d{1,2})?$/.test(value)) {
          callback(new Error('输入值非法，请输入整数或至多两位小数'));
        }
        callback();
      },
      acWetEquipForm: {
        wetACTableData: [], // 工频耐受电压试验(湿)部位表格数据
      },
      showWetACEquip: false, // 工频耐受电压试验(湿)tab显示
      allDefendData: [], // 所有防护数据
      showDefend: false, // 防护试验显示
      defendParams: {
        protectId: [], // 选择防护等级id
        defendTableData: [] // 防护表格数据
      },
      defendLevelList: [], // 防护等级列表
      instrumentId: '', // 仪器id
      editAllParams: [], // 从编辑进入获取测试方案所有信息
      showACEquip: false, // 工频试验显示
      showliEquip: false, // 雷电试验显示
      multSelection: [], // 选中的仪器信息
      liEquipForm: {
        liEquipTableData: [], // 雷电参数配置信息数据
      },
      acEquipForm: {
        acEquipTableData: [], // 工频参数配置信息数据
      },
      accordStandList: [], // 试验依据标准列表
      allInstList: [], // 选择工位出现的所有仪器数据
      displayInstList: [], // 选择工位表格绑定的仪器数据
      dialogVisible: false, // 选择工位弹框
      testPlanInst: [], // 测试方案测试设备
      prodTempList: [], // 试品模板列表
      instStatus: 'all', // 设备状态
      workePosit: '', // 工位
      publicParam: { // 公共参数信息
        productName: '', // 试品名称
        prodTempName: '', // 试品模板
        elevation: '1000', // 海拔
        elevaParam: '1', // 海拔参数
        testType: [], // 试验类型
        accordStand: [], // 试验依据标准
      },
      workePositList: [], // 工位列表
      testTypeList: [], // 试验类型列表
      productNameList: [], // 试品名称列表
      allProdNameList: [], // 所有试品名称列表
      publicParamRules: {}, // 公共参数规则
      liEquipParams: {
        runTimes: 0, // 老练次数
        chargTime: '60', // 充电时间
        firChargVal: '38.3', // 首次充电电压
        counter: 15, // 计数器
        discharge: '1', // 连续放电
        paramC: '',
        paramC1:'',
        paramRf: '',
        paramRt: '',
      },
      acEquipParams: { // 干工频参数配置基本信息
        highSpeed: '', // 高速设置
        lowSpeed: '', // 低速设置
        withstandTime: '60', // 耐压时间
        interval: '5' // 采样间隔
      },
      acWetEquipParams: { // 湿工频参数配置基本信息
        highSpeed: '', // 高速设置
        lowSpeed: '', // 低速设置
        withstandTime: '60', // 耐压时间
        interval: '5', // 采样间隔
        horizCompont: '', // 水平分量
        rainElect: '', // 雨水导电率
        verticalCompont: '', // 垂直分量
        waterTemp: '' // 水温
      },
      liEquipParamsRules: {}, // 雷电参数规则
      acEquipParamsRules: {}, // 干工频参数规则
      activeName: '', // tab分页当前激活
      dataLoading: [false,false,false],
      planFrom: { // 方案基本信息表单
        testPlanName: '', // 方案名称
        description: '' // 方案描述
      },
      planRules: {
        testPlanName: [
          { required: true, message: '请输入方案名称', trigger: 'blur' },
          { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' },
          { validator: sentencedEmpty, trigger: 'blur'}
        ]
      }
    };
  },
  methods: {
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
        if (row.tp_type === 2) { 
          if (columnIndex === 0) {
            return [1,8];
          }
          else if (columnIndex === 1) {
            return [1,5];
          } 
          else if (columnIndex === 2) {
            return [0,0];
          }
          else if (columnIndex === 3) {
            return [0,0];
          }
          else if (columnIndex === 4) {
            return [0,0];
          }
          else if (columnIndex === 5) {
            return [0,0]}
           else if (columnIndex === 6) {
            return [0,0]}
            else if (columnIndex === 7) {
            return [0,0]}
          else if (columnIndex === 8) {
            return [0,0]}
        }
      },
      arraySpanGpMethod({ row, column, rowIndex, columnIndex }) {
        if (row.tp_type === 2) { 
          if (columnIndex === 0) {
            return [1,8];
          }
          else if (columnIndex === 1) {
            return [1,5];
          } 
          else if (columnIndex === 2) {
            return [0,0];
          }
          else if (columnIndex === 3) {
            return [0,0];
          }
          else if (columnIndex === 4) {
            return [0,0];
          }
          else if (columnIndex === 5) {
            return [0,0]}
           else if (columnIndex === 6) {
            return [0,0]}
            else if (columnIndex === 7) {
            return [0,0]}
        }
        
    },
    // 初始化操作
    async init(){
      await this.getProdNameList();
      await this.getTestTypeList();
      await this.getAccordStandList();
      await this.getProtectLevel();
      if(this.$route.query.sign === 'new'){ // 新增方案
        this.testPlanUid = uuid.v1();
      }else{ // 编辑方案
        this.testPlanUid = this.$route.query.planId;
        this.planFrom.testPlanName = this.$route.query.planName;
        this.planFrom.description = this.$route.query.planDesc;
        await this.getTestPlanInfo();
        this.testPlanInst = this.editAllParams.instrument;
        // 查找该方案的试品类型，如果未找到提示用户可能已被删除
        // const productIndex = this.productNameList.findIndex((value) => {
        //   return value.prod_id == this.editAllParams.info.prod_id
        // });
        // if (productIndex === -1) {
        //   this.$message.warning('试品类型可能已被删除,请检查！');
        //   this.publicParam.productName = '';
        // } else {
        //   this.publicParam.productName = this.editAllParams.info.prod_id;
        // }
        // 根据试品类型渲染试品模板，查找该方案选中的试品模板，如果未找到提示用户可能已被删除
        // await this.getProdTempName();
        const tpltIndex = this.prodTempList.findIndex((value) => {
          return value.tplt_id == this.editAllParams.info.tplt_id
        });
        if (tpltIndex === -1) {
          this.$message.warning('试品模板可能已被删除,请检查！');
          this.publicParam.prodTempName = ''
        } else {
          this.publicParam.prodTempName = this.editAllParams.info.tplt_id;
        }
        const testKind = this.editAllParams.publicParams.test_kind.split(',');
        for (let i=0; i<testKind.length; i++) {
          this.publicParam.testType.push(Number(testKind[i]));
        }
        await this.selectTestType(this.publicParam.testType);
        await this.getProdPartInfo();
        this.publicParam.elevation = this.editAllParams.publicParams.sea_level;
        this.publicParam.elevaParam = this.editAllParams.publicParams.ka_m;
        this.publicParam.accordStand = this.editAllParams.publicParams.gjb;
        for (let i=0; i<this.editAllParams.ACParams.length; i++){ // 干工频参数配置模块基本参数
          if (this.editAllParams.ACParams[i].test_kind === 1) {
            this.acEquipParams.withstandTime = this.editAllParams.ACParams[i].withstand_volt_time;
            this.acEquipParams.interval = this.editAllParams.ACParams[i].collect_interval;
            this.acEquipParams.highSpeed = this.editAllParams.ACParams[i].high_speed;
            this.acEquipParams.lowSpeed = this.editAllParams.ACParams[i].low_speed;
          } else { // 湿工频参数配置模块基本参数
            this.acWetEquipParams.withstandTime = this.editAllParams.ACParams[i].withstand_volt_time;
            this.acWetEquipParams.interval = this.editAllParams.ACParams[i].collect_interval;
            this.acWetEquipParams.highSpeed = this.editAllParams.ACParams[i].high_speed;
            this.acWetEquipParams.lowSpeed = this.editAllParams.ACParams[i].low_speed;
            this.acWetEquipParams.horizCompont = this.editAllParams.ACParams[i].horiz_compont;
            this.acWetEquipParams.verticalCompont = this.editAllParams.ACParams[i].vertical_compont;
            this.acWetEquipParams.waterTemp = this.editAllParams.ACParams[i].water_temp;
            this.acWetEquipParams.rainElect = this.editAllParams.ACParams[i].rain_elect;
          }
        }
        if (this.editAllParams.LIParams !== undefined) { // 雷电参数配置模块基本参数
          this.liEquipParams.runTimes = this.editAllParams.LIParams.buffer_cnt;
          this.liEquipParams.chargTime = this.editAllParams.LIParams.charge_time;
          this.liEquipParams.firChargVal = this.editAllParams.LIParams.charge_volt;
          this.liEquipParams.counter = this.editAllParams.LIParams.charge_cnt;
          this.liEquipParams.discharge = this.editAllParams.LIParams.if_discharge.toString();
          this.liEquipParams.distance = this.editAllParams.LIParams.ball_interval;
        }
        if (this.editAllParams.protectInfo !== undefined) { // 气体防护参数配置模块基本参数
          this.defendParams.protectId = this.editAllParams.protectInfo.protectList;
          this.allDefendData = this.editAllParams.protectInfo.protectData;
          // 如果气侯防护选择IPX3、IPX4、IPX5、IPX5W、IPX6需要输入长、宽、高
          for (let i=0; i<this.allDefendData.length; i++){
            if (this.allDefendData[i].protectId === 8 || this.allDefendData[i].protectId === 10 || this.allDefendData[i].protectId === 11 || this.allDefendData[i].protectId === 12 || this.allDefendData[i].protectId === 13) {
              this.defendParams.defendTableData.push(this.allDefendData[i]);
            }
          }
        }
      }
    },
    // arraySpanMethod({ row, column, rowIndex, columnIndex }) {
    //     if (row.tp_type === 2) { 
    //       if (columnIndex === 0) {
    //         return [1,2];
    //       } else if (columnIndex === 1) {
    //         return [0,0];
    //       }else if (columnIndex === 2) {
    //         return [3,1];
    //       }else if (columnIndex === 3) {
    //         return [0,0];
    //       }else if (columnIndex === 4) {
    //         return [0,0];
    //       }else if (columnIndex === 5) {
    //         return [0,0];
    //       }
    //       else if (columnIndex === 6) {
    //         return [7,4];
    //       }
    //     }
    //   },
    
    // 选择防护等级数据变更判断是否需要输入长宽高
    selectDefendType() {
      const protectId = this.defendParams.protectId;
      for (let i=0; i<this.allDefendData.length; i++) { // 删除选择变更后之前选择的选项
        const indexData = protectId.findIndex((value) => {
          return value == this.allDefendData[i].protectId
        })
        if (indexData === -1) {
          // 如果气侯防护选择IPX3、IPX4、IPX5、IPX5W、IPX6将信息从防护表格中删除
          if (this.allDefendData[i].protectId === 8 || this.allDefendData[i].protectId === 10 || this.allDefendData[i].protectId === 11 || this.allDefendData[i].protectId === 12 || this.allDefendData[i].protectId === 13) {
            this.defendParams.defendTableData.splice(this.defendParams.defendTableData.indexOf(this.defendParams.defendTableData.find((item)=>{
              return item.protectId == this.allDefendData[i].protectId
            })));
          }
          this.$delete(this.allDefendData,i);
        }
      }
      for (let i=0; i<protectId.length; i++){ // 添加选择变更后之前未选择的选项
        const indexId = this.defendLevelList.findIndex((value) => {
          return value.protect_id == protectId[i]
        })
        const indexData = this.allDefendData.findIndex((value) => {
          return value.protectId == protectId[i]
        })
        if (indexData === -1){
          if (protectId[i] === 8 || protectId[i] === 10 || protectId[i] === 11 || protectId[i] === 12 || protectId[i] === 13) {
            this.defendParams.defendTableData.push({
              protectId: protectId[i],
              protectLevel: this.defendLevelList[indexId].protect_level,
              productLength: null,
              productWidth: null,
              productHeight: null
            });
          }
          this.allDefendData.push({
            protectId: protectId[i],
            protectLevel: this.defendLevelList[indexId].protect_level,
            productLength: null,
            productWidth: null,
            productHeight: null
          });
        }
      }
    },
    // 获取防护等级数据
    async getProtectLevel(){
      const ret = await this.$http.get("/testPlan/getProtectLevel");
      this.defendLevelList = ret.result;
    },
    // 获取试品类型下拉框数据
    async getProdNameList(){
      const ret = await this.$http.get("/testProdTemplate/getProdTemplate");
      this.prodTempList=JSON.parse(JSON.stringify(ret.result));
      // const ret = await this.$http.get("/testPlan/getProdNameSelect");
      // this.allProdNameList = JSON.parse(JSON.stringify(ret.result));
      // for (let i=0; i<ret.result.length; i++){
      //   this.productNameList.push(ret.result[i][0]);
      // }
    },
    // 根据试品类型渲染试品模板名称
    // getProdTempName(){
    //   this.publicParam.prodTempName = '';
    //   // 查找选中的试品类型在试品类型列表中下标位置
    //   const index = this.productNameList.findIndex((value) => {
    //     return value.prod_id == this.publicParam.productName
    //   });
    //   if (index !== -1) {
    //     this.prodTempList = this.allProdNameList[index];
    //   }
    //   this.$refs['publicParam'].clearValidate();
    // },
    // 获取试验类型列表
    async getTestTypeList(){
      const ret = await this.$http.get("/testPlan/getTestKind");
      this.testTypeList = ret.result;
    },
    // 获取试验依据标准列表
    async getAccordStandList(){
      const ret = await this.$http.get("/testPlan/getTestGjb");
      this.accordStandList = ret.result;
    },
    // 根据选择的试品模板获取试品部位信息
    async getProdPartInfo(){
      this.liEquipForm.liEquipTableData = [];
      this.acEquipForm.acEquipTableData = [];
      this.acWetEquipForm.wetACTableData = [];
      console.info("++++++++++");
      console.info(this.publicParam.prodTempName);
      const params = {
        tpltId: this.publicParam.prodTempName
      }
      const ret = await this.$http.get("/testPlan/getProdBodySelect",{params,});

      console.info(ret);
      if (this.editAllParams.voltParamsDemo === undefined) { // 当新增方案voltParamsDemo字段暂不存在
        this.editAllParams.voltParamsDemo = [];
      }
      // 同步试验模板部位的增加和删除：从编辑进入在根据试验类型电压部位参数中查找模板部位id，进行相应赋值，如果未找到则将api中获取的部位信息添加至相应数据表中
      for (let i=0; i<ret.result.length; i++) {
        const indexLi = this.editAllParams.voltParamsDemo.findIndex((value) => { // 雷电
          return value.tp_id == ret.result[i].tp_id && value.test_kind == 3
        })
        if (indexLi == -1) {
          if(ret.result[i].remark.indexOf('工频')!=-1){
            ret.result[i].if_test="0";
          }
          else{
            ret.result[i].if_test="1";
          }
          console.info("444444444444444444444444444");
          console.info(ret.result);
          this.liEquipForm.liEquipTableData.push(JSON.parse(JSON.stringify(ret.result[i])));
        } else {
          console.info("555555555555555555555555555");
          this.liEquipForm.liEquipTableData.push(JSON.parse(JSON.stringify(this.editAllParams.voltParamsDemo[indexLi])));
        }
        const indexAC = this.editAllParams.voltParamsDemo.findIndex((value) => { // 干工频
          return value.tp_id == ret.result[i].tp_id && value.test_kind == 1
        })
        if (indexAC == -1) {
          console.info(ret.result[i].remark);
          if(ret.result[i].remark.indexOf('雷电')!=-1){
          console.info(i);
            ret.result[i].if_test="0";
          }
          else{
            ret.result[i].if_test="1";
          }
          this.acEquipForm.acEquipTableData.push(JSON.parse(JSON.stringify(ret.result[i])));
        } else {
          this.acEquipForm.acEquipTableData.push(JSON.parse(JSON.stringify(this.editAllParams.voltParamsDemo[indexAC])));
        }
        const indexWet = this.editAllParams.voltParamsDemo.findIndex((value) => { // 湿工频
          return value.tp_id == ret.result[i].tp_id && value.test_kind == 2
        })
        if (indexWet == -1) {
          if(ret.result[i].remark.indexOf('雷电')!=-1){
            ret.result[i].if_test="0";
          }
          else{
            ret.result[i].if_test="1";
          }
          this.acWetEquipForm.wetACTableData.push(JSON.parse(JSON.stringify(ret.result[i])));
        } else {
          this.acWetEquipForm.wetACTableData.push(JSON.parse(JSON.stringify(this.editAllParams.voltParamsDemo[indexWet])));
        }
      }
      console.info(this.liEquipForm.liEquipTableData);
      console.info(this.acEquipForm.acEquipTableData);
    },
    // 获取编辑测试方案所有信息
    async getTestPlanInfo(){
      const params = {
        planId : this.testPlanUid
      }
      const ret = await this.$http.get("/testPlan/getTestPlanData",{params,});
      this.editAllParams = ret.result;
    },
    // 选择试验类型显示对应参数配置
    async selectTestType(value){
      this.showACEquip = false;
      this.showliEquip = false;
      this.showDefend = false;
      this.showWetACEquip = false;
      console.info("++++++++++");
      console.info(value);
      for(let i=0; i<value.length; i++){ // 根据选择的试验类型先判断是否选择该仪器显示对应参数配置模块tab标签页
      
      console.info("+44434354644444444444444444");
        if (value[i] === 1) {
          this.showACEquip = true;
          this.activeName = 'second';
        } else if (value[i] === 3) {
          this.showliEquip = true;
          this.activeName = 'first';
          await this.getACInstParams();
        } else if (value[i] === 9) {
          this.showDefend = true;
          this.activeName = 'third';
        } else if (value[i] === 2) {
          this.showWetACEquip = true;
          this.activeName = 'fourth';
        }
      }
    },
    // 获取雷电设备参数
    async getACInstParams() {
      let params;
      console.info("|||||||||||||||||||||");
      console.info(this.testPlanInst);
      for (let i=0; i<this.testPlanInst.length; i++) {
        if (/雷电冲击耐受电压试验设备/.exec(this.testPlanInst[i].kind_name)!== null && /雷电冲击耐受电压试验设备/.exec(this.testPlanInst[i].kind_name)[0] === '雷电冲击耐受电压试验设备') {
          params = {
            instrId: this.testPlanInst[i].instr_id
          }
          this.instrumentId = this.testPlanInst[i].instr_id;
          const ret = await this.$http.get("/testPlan/getInstrumentParams",{params,});
          for(let j=0; j<ret.result.length; j++) {
            if(/^C\(μF\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramC = ret.result[j].param_val;
            }
            if(/^C1\(pF\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramC1 = ret.result[j].param_val;
            }
            if(/^Rf\(Ω\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramRf = ret.result[j].param_val;
            }
            if(/^Rt\(Ω\)$/.test(ret.result[j].param_name) === true) {
              this.liEquipParams.paramRt = ret.result[j].param_val;
            }
          }
          break
        }
      }
    },
    // 点击选择工位弹出仪器列表，获取所有仪器
    async getTestInstList(){
      let ret;
      this.dialogVisible = true;
      if (this.allInstList.length === 0) {
        ret = await this.$http.get("/testPlan/getInstrumentSelect");
        this.allInstList = JSON.parse(JSON.stringify(ret.result));
        // 将工位信息列出，默认显示数组下标为0的工位信息及其该工位下的所有设备
        for (let i=0; i<ret.result.length; i++) {
          this.workePositList.push({
            'station_id': ret.result[i][0].station_id,
            'station_name': ret.result[i][0].station_name
          })
        }
      }
      this.instStatus = 'all';
      if (this.workePositList.length !== 0) {
        this.workePosit = this.workePositList[0].station_id;
      }
      if (this.allInstList.length !== 0) {
        this.displayInstList = JSON.parse(JSON.stringify(this.allInstList[0]));
      }
      this.selectPositAndStatus()
      this.$refs.multipleTable.clearSelection();
    },
    // 改变工位名称和设备状态更新仪器信息表
    selectPositAndStatus(){
      if (this.allInstList.length !== 0) {
        // 查找搜索条件选中的工位中测试设备对展示仪器列表数据进行赋值
        const index = this.allInstList.findIndex((value) => {
          return value[0].station_id == this.workePosit
        })
        this.displayInstList = JSON.parse(JSON.stringify(this.allInstList[index]));
        if (this.instStatus !== 'all') { // 查找离线或在线设备
          for (let i=0; i<this.displayInstList.length;){
            if (this.displayInstList[i].online_status !== this.instStatus){
              this.$delete(this.displayInstList, i);
            } else {
              i = i+1
            }
          }
        }
        for (let i=0; i<this.testPlanInst.length; i++) { // 剔除已选中的设备
          const index = this.displayInstList.findIndex((value) => {
            return value.instr_id == this.testPlanInst[i].instr_id;
          })
          if (index !== -1) {
            const indexDelet = this.displayInstList.indexOf(this.displayInstList.find((item)=>{
              return item.instr_id == this.testPlanInst[i].instr_id
            }))
            this.$delete(this.displayInstList, indexDelet);
          }
        }
      }
    },
    // 多选选中的仪器
    handleSelectionChange(val) {
      this.multSelection = val;
    },
    // 点击选择工位弹出的弹窗取消按钮功能
    cancelSelect(){
      this.dialogVisible = false;
      if (this.workePositList.length !== 0) {
        this.workePosit = this.workePositList[0].station_id;
      }
      this.instStatus = 'all';
      this.$refs.multipleTable.clearSelection();
    },
    // 提示是否整体替换仪器
    replaceInstrument() {
      this.$confirm('检测到已添加的试验仪器与本次勾选的试验仪器工位名称不相同, 是否全部替换?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.testPlanInst = JSON.parse(JSON.stringify(this.multSelection));
        if (this.showliEquip === true) {
          this.getACInstParams();
        }
      }).catch(() => {
        this.getTestInstList();
      });
    },
    // 点击选择工位弹出的弹窗确定按钮功能
    confirmSelect(){
      if (this.multSelection.length !== 0) {
        if (this.testPlanInst.length !== 0 && this.testPlanInst[0].station_id !== this.multSelection[0].station_id) { // 工位名称不相同
          this.replaceInstrument();
        } else {
          for (let i=0; i<this.multSelection.length; i++) {
            this.testPlanInst.push(this.multSelection[i]);
          }
        }
        if (this.showliEquip === true) { // 如果选择了雷电试验需要更新雷电设备参数
          this.getACInstParams();
        }
      }
      this.dialogVisible = false;
      if (this.workePositList.length !== 0) {
        this.workePosit = this.workePositList[0].station_id;
      }
      this.instStatus = 'all';
    },
    // 删除仪器
    deleteInstrument(index, row){
      this.$delete(this.testPlanInst, index);
    },
    //保存测试方案
    async saveTestPlan(){
      let testKind = '';
      let stand = [];
      // 将选择的测试类型拼接成逗号分隔的数据，eg.1,2,3
      for (let i=0; i<this.publicParam.testType.length; i++) {
        if (i === this.publicParam.testType.length-1) {
          testKind += this.publicParam.testType[i];
        } else {
          testKind += this.publicParam.testType[i] + ',';
        }
      }
      // 根据选择的实验依据标准在试验依据标准列表中查找具体信息
      for (let i=0; i<this.publicParam.accordStand.length; i++) {
        let index = this.accordStandList.findIndex((item) => {
          return item.gjb_id == this.publicParam.accordStand[i]
        })
        stand.push(JSON.parse(JSON.stringify(this.accordStandList[index])));
      }
      const params = {
        'testPlanName': this.planFrom.testPlanName,
        'planId': this.testPlanUid,
        'createUser': JSON.parse(sessionStorage.getItem('userInfo')).user_id,
        'planDesc': this.planFrom.description,
        prodId: this.publicParam.productName,
        instrument: this.testPlanInst,
        tpltId: this.publicParam.prodTempName,
        publicParams:{
          'testKind': testKind,
          seaLevel: Number(this.publicParam.elevation),
          kaM: Number(this.publicParam.elevaParam),
          accordStand: stand
        },
        ACParams: []
      }
      if (this.showliEquip === true) { // 雷电
        params.LIParams = {
          testKind: 3,
          bufferCnt: Number(this.liEquipParams.runTimes),
          chargeTime: Number(this.liEquipParams.chargTime),
          chargeVolt: Number(this.liEquipParams.firChargVal),
          chargeCnt: Number(this.liEquipParams.counter),
          ifDischarge: Number(this.liEquipParams.discharge),
          voltParams: this.liEquipForm.liEquipTableData
        }
      }
      if (this.showACEquip === true) { // 干工频
        params.ACParams.push({
          testKind: 1,
          highSpeed: Number(this.acEquipParams.highSpeed),
          lowSpeed: Number(this.acEquipParams.lowSpeed),
          collectInterval: Number(this.acEquipParams.interval),
          withstandVoltTime: Number(this.acEquipParams.withstandTime),
          voltParams: this.acEquipForm.acEquipTableData
        })
      }
      if (this.showWetACEquip === true) { // 湿工频
        params.ACParams.push({
          testKind: 2,
          highSpeed: Number(this.acWetEquipParams.highSpeed),
          lowSpeed: Number(this.acWetEquipParams.lowSpeed),
          collectInterval: Number(this.acWetEquipParams.interval),
          withstandVoltTime: Number(this.acWetEquipParams.withstandTime),
          horizCompont: Number(this.acWetEquipParams.horizCompont),
          waterTemp: Number(this.acWetEquipParams.waterTemp),
          rainElect: Number(this.acWetEquipParams.rainElect),
          verticalCompont:Number(this.acWetEquipParams.verticalCompont),
          voltParams: this.acWetEquipForm.wetACTableData
        })
      }
      if (this.showDefend === true) { // 气体防护
        for (let i=0; i<this.defendParams.defendTableData.length; i++) {
          const index = this.allDefendData.findIndex((value) => {
            return value.protectId == this.defendParams.defendTableData[i].protectId
          })
          this.allDefendData[index].productHeight = this.defendParams.defendTableData[i].productHeight;
          this.allDefendData[index].productLength = this.defendParams.defendTableData[i].productLength;
          this.allDefendData[index].productWidth = this.defendParams.defendTableData[i].productWidth;
        }
        params.protectData = this.allDefendData;
      }
      // console.info('--------下发保存参数-------------')
      // console.info(params)
      let ret = await this.$http.post("/testPlan/saveTestPlan",params);
      if (ret.code === 403) {
        this.$message.warning(ret.message)
      }
      if (ret.code === 200 && this.instrumentId !== '') {
        const insparams = {
          instr_id: this.instrumentId,
          instrumentParams: [{
            param_name: 'C(μF)',
            param_val: this.liEquipParams.paramC
          },{
            param_name: 'C1(pF)',
            param_val: this.liEquipParams.paramC1
          },{
            param_name: 'Rf(Ω)',
            param_val: this.liEquipParams.paramRf
          },{
            param_name: 'Rt(Ω)',
            param_val: this.liEquipParams.paramRt
          }]
        }
        // console.info('--------下发insparams-------------')
        // console.info(insparams)
        ret = await this.$http.post("/testPlan/updateInstrumentParams",insparams);
      }
      if(ret.code === 200){
        this.$router.push({
          path: '/TestPlan'
        });
      }
    },
    // 保存前的校验
    saveValidate(){
      let saveFlag = 0;
      for (let i=0; i<this.publicParam.testType.length; i++) { // 根据选择的试验类型检查工频和雷电设备是否选择
        let kindName = '';
        if(this.publicParam.testType[i] == 1 || this.publicParam.testType[i] == 2) {
          kindName = '工频耐受电压试验设备';
        } else if (this.publicParam.testType[i] == 3) {
          kindName = '雷电冲击耐受电压试验设备';
        } else {
          continue
        }
        const index = this.testPlanInst.findIndex((value) => {
          return value.kind_name == kindName
        })
        if (index == -1) {
          this.$message.error('您未选择'+kindName);
          return
        }
      }
      this.$refs['planFrom'].validate((valid) => {
        if (valid) {
          saveFlag = 1;
        } else {
          saveFlag = 0;
        }
      });
      if (saveFlag === 0) {
        this.$message.error('您未填写测试方案名称!');
        return
      }
      this.$refs['publicParam'].validate((valid) => {
        if (valid) {
          saveFlag = 1;
        }else{
          saveFlag = 0;
        }
      });
      if (saveFlag === 0) {
        this.$message.error('您未填写完整公共参数!');
        return
      }
      if (this.showliEquip === true) {
        this.$refs['liEquipParams'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中雷电冲击耐受电压试验参数!');
          return
        }
        this.$refs['liEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中雷电部位电压参数!');
          return
        }
      }
      if (this.showACEquip === true) {
        this.$refs['acEquipParams'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验参数!');
          return
        }
        this.$refs['acEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验部位电压参数!');
          return
        }
      }
      if (this.showWetACEquip === true) {
        this.$refs['acWetEquipParams'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验(湿)参数!');
          return
        }
        this.$refs['acWetEquipForm'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整参数配置中工频耐受电压试验(湿)部位电压参数!');
          return
        }
      }
      if (this.showDefend === true) {
        this.$refs['defendParams'].validate((valid) => {
          if (valid) {
            saveFlag = 1;
          }else{
            saveFlag = 0;
          }
        });
        if (saveFlag === 0) {
          this.$message.error('您未填写完整气候防护参数!');
          return
        }
      }
      this.saveTestPlan();
    },
    // 取消方案保存
    toCanale(){
      this.$router.push({
        path: '/TestPlan'
      });
    }
  },
  mounted() {
    this.init();
  }
};
</script>
<style lang="scss" scoped>
@import "./EditOrNewTestPlan.scss";
</style>

